var mix = (function (mix) {

mix.vector2d = {};
var vector2d = mix.vector2d;

var Vector2D = function( x, y) {
	this.x = x;
	this.y = y;
}

Vector2D.prototype = {
    add : function( v) {
	    this.x += v.x;
	    this.y += v.y;
	    return this;
    },

    sub : function( v) {
	    this.x -= v.x;
	    this.y -= v.y;
	    return this;
    },

    mul : function( s) {
	    this.x *= s;
	    this.y *= s;
	    return this;
    },

    div : function( s) {
	    this.x /= s;
	    this.y /= s;
	    return this;
    },
    
    length : function() {
        return Math.sqrt( this.x * this.x + this.y * this.y);
    },
    
    normlize : function() {
        var l = this.length();
        x /= l;
        y /= l;
        return this;
    },
}

vector2d.create = function(x, y) {
    return new Vector2D(x, y);
}

vector2d.add = function( v1, v2) {
	return vector2d.create( v1.x + v2.x , v1.y + v2.y);
}

vector2d.sub = function( v1, v2) {
	return vector2d.create( v1.x - v2.x , v1.y - v2.y);
}

vector2d.mul = function( v, s) {
	return vector2d.create( v.x * s + v.y * y);
}

vector2d.length = function( v) {
	return Math.sqrt( v.x * v.x + v.y * v.y);
}

vector2d.normalize = function( v) {
	var l = vector2d.length(v);
	return new Vector2D( v.x / l, v.y / l);
}

vector2d.dot = function ( v1, v2) {
	return v1.x * v2.x + v1.y * v2.y;
}

vector2d.lerp = function( v1, v2, t) {
	return vector2d.add( v1, vector2d.sub( v2, v1).mul(t));
}

return mix;           
      
}(mix || {}));